package com.hxy.subject.domain.service.impl;

import com.hxy.subject.domain.convert.SubjectCategoryConverter;
import com.hxy.subject.domain.entity.SubjectCategoryBO;
import com.hxy.subject.domain.service.ISubjectCategoryDomainService;
import com.hxy.subject.infra.basic.entity.SubjectCategory;
import com.hxy.subject.infra.basic.service.SubjectCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author haoxuyang
 * @Date 2024/9/2 18:44
 */
@Service
public class SubjectCategoryDomainServiceImpl implements ISubjectCategoryDomainService {
    @Resource
    SubjectCategoryService subjectCategoryService;

    public void add(SubjectCategoryBO bo) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.subjectCategoryBoToCategory(bo);
        subjectCategoryService.insert(subjectCategory);
    }

    public List<SubjectCategoryBO> queryPrimaryCategory(SubjectCategoryBO bo) {
        SubjectCategory subjectCategory=new SubjectCategory();
        subjectCategory.setParentId(0L);
        subjectCategory.setIsDeleted(0);
        subjectCategory.setCategoryType(bo.getCategoryType());
        List<SubjectCategory> subjectCategoryList=subjectCategoryService.queryCategory(subjectCategory);
        List<SubjectCategoryBO> subjectCategoryBOList = SubjectCategoryConverter.INSTANCE.subjectCategoryToBoList(subjectCategoryList);
        return subjectCategoryBOList;
    }

    public List<SubjectCategoryBO> queryCategoryByPrimary(SubjectCategoryBO bo) {
        SubjectCategory subjectCategory=new SubjectCategory();
        subjectCategory.setIsDeleted(0);
        subjectCategory.setParentId(bo.getParentId());
        List<SubjectCategory> subjectCategoryList=subjectCategoryService.queryCategory(subjectCategory);
        List<SubjectCategoryBO> subjectCategoryBOList = SubjectCategoryConverter.INSTANCE.subjectCategoryToBoList(subjectCategoryList);
        return subjectCategoryBOList;
    }

    public void update(SubjectCategoryBO bo) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.subjectCategoryBoToCategory(bo);
        subjectCategoryService.update(subjectCategory);
    }

    public void delete(SubjectCategoryBO bo) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.subjectCategoryBoToCategory(bo);
        subjectCategoryService.delete(subjectCategory);
    }
}
